
<!DOCTYPE html>
<html lang="en" xmlns:v-model="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="../../js/vue/vue.js"></script>
    <script src="../../js/jquery/jquery.js"></script>
</head>
<body>
<div id="app">
    <form id="editForm">
        <input type="hidden" name="id" v-model:value="brand.id"><br/>
        用户名: <input name="brandName"  v-model:value="brand.brandName"><br/>
        年龄: <input name="brandEncoding"  v-model:value="brand.brandEncoding"><br/>
        <input type="button" value="提交" @click="update()">
    </form>
</div>
<script>
    //获取url上的请求参数
    function getParams() {
        //获取问号及问号后面的内容
        var url = window.location.search;
        var params = new Object();
        if (url.indexOf("?") != -1) {
            //截取问号后面的内容,再使用&分割多个属性
            var arr = url.substr(1).split("&");
            for (var i = 0; i < arr.length; i++) {
                //使用=分割为keyvalue
                var keyValue = arr[i].split("=");
                params[keyValue[0]] = keyValue[1];
            }
        }
        return params;
    }
    var vue = new Vue({
        el: "#app",
        data: {
            brand:{}
        },
        methods: {
            update: function () {
                $.post("http://localhost:8080/brands/update", $("#editForm").serialize(), function (data) {
                    if (data.code == 200) {
                        window.location.href = "http://localhost/view/brand/list.html"
                    }
                })
            }
        },
        mounted:function () {
            //1 获取url后面的参数
            var map=getParams(); //{id: '3', age: '21'}
            console.log(map);
            // 2发送ajax请求查询数据
            var _this=this;
            //发送请求加载数据
            $.get("http://localhost:8080/brands/detail",{id:map.id},function (data) {
                if(data.code==200){
                    _this.brand=data.data
                }else{
                    alert(data.msg);
                }
            })

        }

    });
</script>
</body>
</html>